<?php
class TbfTemplate {
    //引入一个模板,传入数据,并且输出到浏览器(或标准输出)
    public static function RenderAndEcho($tplName,$d=array()){
        $__selfTemplatePath = TbfTemplate::getPathByName($tplName);
        if (!file_exists($__selfTemplatePath)){
            throw new \Exception('[TbfTemplate] template file '.$tplName.' can not found');
        }
        if (is_array($d)) {
            extract($d);
        }
        include $__selfTemplatePath;
    }

    public static function getPathByName($name){
        return TbfConfig::$TplPath.'/'.str_replace('.','/',$name).'.php';
    }
    //引入一个模板,传入数据,并且返回模板内容

    public static function Render($tplName,$d=array()){
        $__selfTemplatePath = TbfTemplate::getPathByName($tplName);
        if (!file_exists($__selfTemplatePath)){
            throw new \Exception('[TbfTemplate] template file '.$tplName.' can not found');
        }
        if (is_array($d)) {
            extract($d);
        }
        ob_start();
        include $__selfTemplatePath;
        return ob_get_clean();
    }
} 
